﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_DeleteSmallGroup')
BEGIN
    PRINT 'Dropping Procedure proc_cm_DeleteSmallGroup'
    DROP  Procedure  proc_cm_DeleteSmallGroup
END
GO

PRINT 'Creating Procedure proc_cm_DeleteSmallGroup'
GO

CREATE PROCEDURE [dbo].[proc_cm_DeleteSmallGroup]
	@pSmallGroupId uniqueidentifier
AS
BEGIN
	SET NOCOUNT ON

	UPDATE [dbo].[tbl_member]
	SET [smallgroup_id] = NULL
	WHERE [smallgroup_id] = @pSmallGroupId

	DELETE FROM [dbo].[tbl_member_smallgroup]
	WHERE [smallgroup_id] = @pSmallGroupId

	DELETE FROM [dbo].[tbl_smallgroup]
	WHERE [smallgroup_id] = @pSmallGroupId
END
GO

GRANT EXEC ON dbo.proc_cm_DeleteSmallGroup TO PUBLIC
GO

